home *** CD-ROM | disk | FTP | other *** search
- /* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- Icon Lister
-
- Demo the List Object.
- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */
-
- /* |||||||||| defines |||||||||| */
- #define ICONWINKIND 4242
-
- #include <oops.h>
-
- #ifndef CLASS_LISTOBJ
- #include "CListObj.h"
- #endif
-
- #ifndef CLASS_ICONITEMOBJ
- #include "CIconItemObj.h"
- #endif
-
- /* |||||||||| Globals |||||||||| */
- int DoneFlag;
- EventRecord TheEvent;
- Point TheMousePt;
- Rect DragRect;
- MenuHandle AppleMenu;
- MenuHandle FileMenu;
- MenuHandle EditMenu;
-
- /* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */
- main ( )
- {
- WindowPtr whichWindow;
- char key;
- CListObj *anIconList;
- GrafPtr oldPort;
-
- Initialize ( );
- while ( !DoneFlag ) {
-
- GetNextEvent ( everyEvent, &TheEvent );
- switch ( TheEvent.what ) {
- case activateEvt:
- whichWindow = (WindowPtr) TheEvent.message;
- if ( ((WindowPeek) whichWindow)->windowKind == ICONWINKIND ) {
- anIconList = (CListObj *) GetWRefCon (whichWindow );
- anIconList->ActivateList ( TheEvent.modifiers & activeFlag );
- }
- break;
- case updateEvt:
- whichWindow = (WindowPtr) TheEvent.message;
- if ( ((WindowPeek) whichWindow)->windowKind == ICONWINKIND ) {
- GetPort ( &oldPort );
- SetPort ( whichWindow );
- anIconList = (CListObj *) GetWRefCon (whichWindow );
- BeginUpdate ( whichWindow );
- anIconList->UpdateList ( whichWindow->visRgn );
- EndUpdate ( whichWindow );
- SetPort ( oldPort );
- }
- break;
- case mouseDown:
- switch ( FindWindow ( TheEvent.where, &whichWindow ) ) {
- case inMenuBar:
- DoMenu ( MenuSelect ( TheEvent.where ) );
- break;
- case inSysWindow:
- SystemClick ( &TheEvent, whichWindow );
- break;
- case inDrag:
- if ( ((WindowPeek) whichWindow)->windowKind == ICONWINKIND ) {
- DragWindow ( whichWindow, TheEvent.where, &DragRect );
- }
- break;
- case inGoAway:
- if ( ((WindowPeek) whichWindow)->windowKind == ICONWINKIND ) {
- if ( TrackGoAway ( whichWindow, TheEvent.where ) ) {
- CloseIconWindow ( whichWindow );
- }
- }
- break;
- case inContent:
- if ( ((WindowPeek) whichWindow)->windowKind == ICONWINKIND ) {
- if ( whichWindow != FrontWindow ( ) ) SelectWindow ( whichWindow );
- else {
- SetPort ( whichWindow );
- TheMousePt = TheEvent.where;
- GlobalToLocal ( &TheMousePt );
- anIconList = (CListObj *) GetWRefCon (whichWindow );
- anIconList->MouseInList ( TheMousePt, TheEvent.modifiers );
- }
- }
- break;
- }
- break;
- case autoKey:
- case keyDown:
- key = (char) (TheEvent.message & charCodeMask);
- if ( TheEvent.modifiers & cmdKey ) DoMenu ( MenuKey ( key ) );
- break;
- case nullEvent:
- SystemTask ( );
- break;
- }
- }
- }
-
- /* |||||||||||||||||||| */
- Initialize ( )
- {
- Handle h;
- Str255 volName;
-
- /*** init the mac rom stuff */
- InitGraf ( &thePort );
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs ( 0L );
- InitCursor ();
- FlushEvents ( everyEvent, 0 );
-
- MaxApplZone (); MoreMasters (); MoreMasters ();
- GetNextEvent ( everyEvent, &TheEvent );
- GetNextEvent ( everyEvent, &TheEvent );
- GetNextEvent ( everyEvent, &TheEvent );
- GetNextEvent ( everyEvent, &TheEvent );
-
- /*** set up a few globals ... */
- DoneFlag = false;
- DragRect = screenBits.bounds;
-
- /*** read in the menus */
- AppleMenu = GetMenu ( 1000 );
- InsertMenu ( AppleMenu, 0 );
- AddResMenu ( AppleMenu, 'DRVR' );
- FileMenu = GetMenu ( 1001 );
- InsertMenu ( FileMenu, 0 );
- EditMenu = GetMenu ( 1002 );
- InsertMenu ( EditMenu, 0 );
- DrawMenuBar ();
- }
-
- /* |||||||||||||||||||| */
- DoMenu ( long mResult )
- {
- int theMenu, theItem, i;
- Str255 aname, freestr, maxstr;
- GrafPtr curport;
- TEHandle te;
- MenuHandle new;
- long sz, type;
- int mark, *menuNum;
- WindowPtr aWin;
-
- theItem = LoWord ( mResult );
- theMenu = HiWord ( mResult );
- switch ( theMenu ) {
- case 1000:
- if ( theItem == 1 ) DoAbout ( );
- else {
- GetItem ( AppleMenu, theItem, aname );
- GetPort ( &curport );
- OpenDeskAcc ( aname );
- SetPort ( curport );
- }
- break;
- case 1001:
- switch ( theItem ) {
- case 1:
- OpenIconWindow ( );
- break;
- case 2:
- aWin = FrontWindow ( );
- if ( aWin != 0L && ((WindowPeek) aWin)->windowKind == ICONWINKIND )
- CloseIconWindow ( aWin );
- break;
- case 4:
- DoneFlag = true;
- break;
- }
- break;
- case 1002:
- break;
- }
-
- HiliteMenu(0);
- }
-
- /* |||||||||||||||||||| */
- OpenIconWindow ( )
- {
- Point where;
- SFReply theFile;
- SFTypeList typs;
- WindowPtr theWin;
- CListObj *theList;
- Rect bounds;
- int fileRef;
-
- /*** get the file */
- where.h = where.v = 42;
- SFGetFile ( where, 0L, 0L, -1, typs, 0L, &theFile );
- if ( theFile.good ) {
-
- /*** open the file */
- SetVol ( NULL, theFile.vRefNum );
- fileRef = OpenResFile (theFile.fName );
- if ( fileRef < 0 ) {
- StopAlert ( 1000, NULL );
- return;
- }
-
- /*** set up the window, start it's list object, fill it with icons */
- theWin = GetNewWindow ( 1000, 0L, -1L);
- ((WindowPeek) theWin)->windowKind = ICONWINKIND;
- SetWTitle ( theWin, theFile.fName );
- bounds = theWin->portRect;
- theList = new ( CListObj );
- theList->IList ( &bounds, 40, true, lOnlyOne, theWin );
- theList->DrawingOn ( false );
-
- /*** fill the list with ICONs */
- FillIconList ( fileRef, theList );
- theList->DrawingOn ( true );
- CloseResFile ( fileRef );
- SetWRefCon ( theWin, (long) theList );
- }
- }
-
- /* |||||||||||||||||||| */
- FillIconList ( int aFile, CListObj *aList )
- {
- int i, iconID, numIcons;
- ResType iconType;
- Str255 iconName;
- CIconItemObj *anIcon;
- Handle iconHan;
-
- /*** get each icon, create a new list item object, add it to the list */
- numIcons = Count1Resources ( 'ICON' );
- for ( i = 1; i <= numIcons; ++i ) {
- if ( (iconHan = Get1IndResource ( 'ICON', i )) != 0L ) {
- GetResInfo ( iconHan, &iconID, &iconType, iconName );
-
- anIcon = new ( CIconItemObj );
- anIcon->id = iconID;
- BlockMove ( iconName, anIcon->name, 255L );
- DetachResource ( iconHan );
- anIcon->bits = iconHan;
-
- aList->Add ( anIcon );
- }
- }
- }
-
- /* |||||||||||||||||||| */
- CloseIconWindow ( WindowPtr theWin )
- {
- CListObj *theIconList;
- CIconItemObj *anIcon;
- int i, num;
-
- /*** throw away it's contents and close the window */
- theIconList = (CListObj *) GetWRefCon ( theWin );
-
- /*** throw away the CIconList objects, most efficient to go from the end of the list to the start */
- theIconList->DrawingOn ( false );
- num = theIconList->NumObjs();
- for ( i = num; i >0; --i ) {
- anIcon = (CIconItemObj *) theIconList->GetIndObject ( i );
- theIconList->Remove ( anIcon );
- DisposHandle ( anIcon->bits );
- delete ( anIcon );
- }
- theIconList->Dispose ( );
- DisposeWindow ( theWin );
- }
-
- /* |||||||||||||||||||| */
- DoAbout ( )
- {
- Alert ( 4242, 0L );
- }
-
-